package com.njegovanobradovic.icet.pages;

import java.util.List;

import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.njegovanobradovic.icet.facade.Controller;
import com.njegovanobradovic.icet.metamodel.Chat;
import com.njegovanobradovic.icet.metamodel.Message;
import com.njegovanobradovic.icet.metamodel.User;

public class HistoryChat {
	@Persist
	private Chat chat;
	@Property
	private Message message;
	@Property
	private User user;
	@Inject
	private Controller controller;

	public Chat getChat() {
		return chat;
	}

	public void setChat(Chat chat) {
		this.chat = chat;
	}

	public List<Message> getMessages() {
		return controller.getChatMessages(getChat());
	}
	
	public List<User> getUsers(){
		return getChat().getUsers();
	}
	
	@InjectPage
	private Details detailsPage;
	@OnEvent(component = "detailsLink")
	Object onShowDetails(String username) {
		detailsPage.setUser(controller.getUser(username));
		return detailsPage;
	}
}
